


//
//  UIBarButton+Extension.swift
//  WeiBo
//
//  Created by crazyfish on 16/3/11.
//  Copyright © 2016年 crazyfish. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    /**
     快速创建一个UIBarButtonItem
     
     - parameter imageNamed: 显示的图片名称
     - parameter target:     事件触发的时候调用谁的方法
     - parameter action:     调用什么方法
     
    
     */
    //便利构造函数????在便利构造函数里面调用其他的构造函数只能使用self
    convenience init(imageNamed: String? = nil , title : String? = nil, target: AnyObject?, action: Selector) {
        self.init()
        let button = UIButton()
        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        if let t = title{
            
            button.setTitle(t, forState: .Normal)
            button.setTitleColor(UIColor(colorLiteralRed: 52/255, green: 52/255, blue: 52/255, alpha: 1), forState: .Normal)
            button.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
            button.titleLabel?.font = UIFont.systemFontOfSize(14)
            
            
        }
        
        if let named = imageNamed{
            button.setImage(UIImage(named: named), forState: .Normal)
            button.setImage(UIImage(named: "\(named)_highlighted"), forState: .Highlighted)
        }
        
        button.sizeToFit()
        customView = button
        
        }
    }